﻿using Gargoyle.Roton;
using System;
using System.Collections.Generic;
using System.Text;

namespace Gargoyle.ZZT
{
    public class BoardCollection : System.Collections.ReadOnlyCollectionBase
    {
        private ElementCollection elements;

		/// <summary>
		/// Create a new collection of boards.
		/// </summary>
		/// <param name="newElements">Element collection to use.</param>
        public BoardCollection(ElementCollection newElements)
        {
            elements = newElements;
        }

		/// <summary>
		/// Get or set a board in the collection.
		/// </summary>
		/// <param name="index"></param>
		/// <returns></returns>
        public Board this[int index]
        {
            get
            {
                return (Board)InnerList[index];
            }
            set
            {
                InnerList[index] = value;
            }
        }

		/// <summary>
		/// Add a board to the collection.
		/// </summary>
        public void Add(Board item)
        {
            InnerList.Add(item);
        }

		/// <summary>
		/// Get the index of a board in this collection.
		/// </summary>
		public int IndexOf(Board item)
        {
            return InnerList.IndexOf(item);
        }

		/// <summary>
		/// Remove a board from the collection.
		/// </summary>
		public void Remove(Board item)
        {
            RemoveBoard(IndexOf(item));
        }

		/// <summary>
		/// Remove a board from a specific index in the collection.
		/// </summary>
		public void RemoveAt(int index)
        {
            RemoveBoard(index);
        }

		/// <summary>
		/// Remove a board from the collection and modify its target board properties (for passages, etc) so that they point properly.
		/// </summary>
		private void RemoveBoard(int index)
        {
            Board board = this[index];

            for (int i = 0; i < board.Things.Count; i++)
            {
				// todo: reassign destination board exits and passage targets.
            }

            InnerList.RemoveAt(index);
        }
    }
}
